import CodeBlock from "@theme/CodeBlock";

# Lunary

This page covers how to use [Lunary](https://lunary.ai?utm_source=langchain&utm_medium=js&utm_campaign=docs) with LangChain.

## What is Lunary?

Lunary is an [open-source](https://github.com/lunary-ai/lunary) platform that provides observability (tracing, analytics, feedback tracking), prompt templates management and evaluation for AI apps.

<video controls width="100%">
  <source src="https://lunary.ai/videos/demo-annotated.mp4" />
</video>

## Installation

Start by installing the Lunary package in your project:

```bash npm2yarn
npm install lunary
```

## Setup

Create an account on [lunary.ai](https://lunary.ai?utm_source=langchain&utm_medium=js&utm_campaign=docs). Then, create an App and copy the associated `tracking id`.

Once you have it, set it as an environment variable in your `.env`:

```bash
LUNARY_APP_ID="..."

# Optional if you're self hosting:
# LUNARY_API_URL="..."
```

If you prefer not to use environment variables, you can set your app ID explictly like this:

import LunaryCustomAppId from "@examples/callbacks/lunary_custom_app_id.ts";

<CodeBlock language="typescript">{LunaryCustomAppId}</CodeBlock>

You can now use the callback handler with LLM calls, chains and agents.

## Quick Start

import LunaryQuickstart from "@examples/callbacks/lunary_quickstart.ts";

<CodeBlock language="typescript">{LunaryQuickstart}</CodeBlock>

## LangChain Agent Tracing

When tracing chains or agents, make sure to include the callback at the run level so that all sub LLM calls & chain runs are reported as well.

import LunaryLangchainAgent from "@examples/callbacks/lunary_langchain_agent.ts";

<CodeBlock language="typescript">{LunaryLangchainAgent}</CodeBlock>

## Tracking users

You can track users by adding `userId` and `userProps` to the metadata of your calls:

import LunaryUsers from "@examples/callbacks/lunary_users.ts";

<CodeBlock language="typescript">{LunaryUsers}</CodeBlock>

## Tagging calls

You can tag calls with `tags`:

import LunaryTags from "@examples/callbacks/lunary_tags.ts";

<CodeBlock language="typescript">{LunaryTags}</CodeBlock>

## Usage with custom agents

You can use the callback handler combined with the `lunary` module to track custom agents that partially use LangChain:

import LunaryCustomAgent from "@examples/callbacks/lunary_custom_agent";

<CodeBlock language="typescript">{LunaryCustomAgent}</CodeBlock>

## Full documentation

You can find the full documentation of the Lunary LangChain integration [here](https://lunary.ai/docs/langchain?utm_source=langchain&utm_medium=js&utm_campaign=docs).

## Support

For any question or issue with integration you can reach out to the Lunary team via [email](mailto:vince@lunary.ai) or livechat on the website.
